import fetch from 'common/src/utils/fetch';

function selectCoursesCountList(data) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/selectCoursesCountList',
        method: 'post',
        data
    });
}

function getStudentList(data, type) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/' + type,
        method: 'post',
        data
    });
}


function renovate(data) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/renovate',
        method: 'post',
        data
    });
}

function exporCurentPage(data) {
    window.open('/api/cultureservice/bclCulturePlan/exporCurentPage' + getParams(data));
}

function exportNoSelCourseCountStudentInfo(data) {
    window.open('/api/cultureservice/bclCulturePlan/exportNoSelCourseCountStudentInfo' + getParams(data));
}


function getParams(params) {
    var paramsData = [];
    for (const key in params) {
        params[key] &&
            paramsData.push(
                key + '=' + params[key]
            );
    }
    if (paramsData.length)
        return '?' + paramsData.join('&');
    else
        return '';
}

const courseStatisticsApi = {
    'selectCoursesCountList': selectCoursesCountList,
    'getStudentList': getStudentList,
    'renovate': renovate,
    'exporCurentPage': exporCurentPage,
    'exportNoSelCourseCountStudentInfo': exportNoSelCourseCountStudentInfo
}

export default courseStatisticsApi;